package com.ruoyi.demo02;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @Author syc
 * @Date Created in 14:43 2022/8/15
 * @Description 线程创建方式3实现Callbale接口
 */
public class TestCallable implements Callable<Boolean> {
    @Override
    public Boolean call() throws Exception {
        System.out.println("调用了方法");
        return true;
    }


    public static void main(String[] args) {
        TestCallable t1 = new TestCallable();
        TestCallable t2 = new TestCallable();
        ExecutorService executorService= null;
        try {
           //创建执行服务
            executorService = Executors.newFixedThreadPool(2);
            // 提交执行
            Future<Boolean> b1 = executorService.submit(t1);
            Future<Boolean> b2 = executorService.submit(t2);
            executorService.submit(t2);
            // 获取结果
            boolean rs1 =  b1.get();
            boolean rs2 = b2.get();
           System.out.println(rs1 + "........" + rs2);

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(executorService != null) {
                executorService.shutdownNow();
            }
        }

    }

}
